<?php


namespace App\Server\Model;

use App\Server\Cache\Cache;

class Admin extends Model
{
    protected $dateFormat = 'U';
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'admin';

	public function admincate()
    {
        //关联角色表
        return $this->belongsTo('AdminCate');
    }

    public function article()
    {
        //关联文章表
        return $this->hasOne('Article');
    }

    public function log()
    {
        //关联日志表
        return $this->hasOne('AdminLog');
    }

    public function attachment()
    {
        //关联附件表
        return $this->hasOne('Attachment');
    }



    public function getValueByWhere($where,$field){
        return $this->where($where)->value($field);
    }



    public function dataSave($data,$where,$field=true,$updateType=true,$type='one'){
        if ($type=='one'){
            return $this->allowField($field)->isUpdate($updateType)->save($data,$where);
        }elseif ($type=='all'){
            return $this->saveAll($data);
        }
    }

}
